﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

// qt headers
#include <QObject>
#include <QStyledItemDelegate>
#include <QPushButton>
#include <QItemDelegate>
#include <QPointer>


namespace gmepgcs
{
    struct IProjectComponent;
}

namespace gmepgcs
{
    class ListItemDelegate : public QStyledItemDelegate
    {
        Q_OBJECT

    public:
        explicit ListItemDelegate(QWidget *parent = nullptr);
        ~ListItemDelegate();
        
        void SetIsEditOperationVisible(bool isEditOperationVisible = true);
    public:
        void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
        bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index);

    signals:
        void LoadComponentRequired(QAbstractItemModel *model, const QModelIndex &index);
        void SyncComponentRequired(QAbstractItemModel *model, const QModelIndex &index);
        void DeleteComponentRequired(QAbstractItemModel *model, const QModelIndex &index);
        void PlaceComponentRequired(QAbstractItemModel *model, const QModelIndex &index);
        
    private:
        void setMouseHover(bool mouseHover, QAbstractItemModel *model, const QModelIndex &index);
        void DrawButtonByStatus(QPainter *painter, const QStyleOptionViewItem &option, int status) const;
        void DrawButton(QPainter *painter, const QRect &rect, const QPalette &palette, const QString &text) const;

    private:
        //QPushButton *m_pushButton;
        //QImage *m_image;
        //QImage *m_icon;
        //QImage *m_iconHover;
        //QImage *m_ticked;
        bool m_mouseHover;
        bool m_IsOverButtonL; // 单按钮或双按钮左
        bool m_IsOverButtonR; // 双按钮右
        int m_mouseCurrentRow;

        QPointer<QWidget> m_parentWidget;
        bool m_isEditOperationVisible = true; // 是否显示编辑行为的按钮（checkbox, 同步,删除,载入）
    };
}



